package bao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Zhuce
 */
@WebServlet("/Zhuce")
public class Zhuce extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Zhuce() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
	try {request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	Class.forName("com.mysql.cj.jdbc.Driver");
	Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yj?autoReconnect=true&serverTimezone=GMT","root","root");
	if(request.getParameter("zl").toString().equals("yh")) {
	PreparedStatement j=con.prepareStatement("insert into user(name,psw)value(?,?)");
	j.setString(1, request.getParameter("name"));
	j.setString(2, request.getParameter("psw"));

	j.executeUpdate();j.close();
	
	}
	if(request.getParameter("zl").toString().equals("qy")) {
		PreparedStatement j=con.prepareStatement("insert into qy(name,psw)value(?,?)");
		j.setString(1, request.getParameter("name"));
		j.setString(2, request.getParameter("psw"));

		j.executeUpdate();j.close();}
	
	if(request.getParameter("zl").toString().equals("gly")) {
		PreparedStatement j=con.prepareStatement("insert into manager(name,psw)value(?,?)");
		j.setString(1, request.getParameter("name"));
		j.setString(2, request.getParameter("psw"));

		j.executeUpdate();j.close();}



	con.close();
	response.sendRedirect("start.jsp");
			

	}catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	}
		
		
		
		
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
